package com.yy.job.common.enums;

import java.text.MessageFormat;

/**
 * 异常定义
 * 
 * @author eleven.li
 *
 */
public enum ErrorCodeEnum {
	
	CMN_RUNTIME_ERROR("20001", "execute failed,{0}"), 
	CMN_INITIAL_ERROR("20002", "initial failed,{0}"),
	CMN_PARAMETER_ERROR("20003", "parameter is wrong,{0}"),
	
	CHECK_PROJECT_CONFIG("30001", "yy-job config wrong"),
	CHECK_PROJECT_ERROR("30002", "project config wrong,error={0}"),
	CHECK_MODULE_ERROR("30003", "module config wrong,error={0}"),
	CHECK_MODULE_CONFIG("30004", "module config wrong,moduleCode={0},error={1}"),
	CHECK_JOB_ERROR("30005", "job config wrong,moduleCode={0},error={1}"),
	CHECK_JOB_CONFIG("30006", "job config wrong,moduleCode={0},jobCode={1},error={2}"),
	CHECK_STEP_ERROR("30007", "step config wrong,moduleCode={0},jobCode={1},error={2}"),
	CHECK_STEP_CONFIG("30008", "step config wrong,moduleCode={0},jobCode={1},stepCode={2}, error={3}"),

	CHECK_JOBCODE_NOT_EMPTY("40001", "jobCode is empty"), 
	CHECK_JOBCODE_NOT_ERROR("40002", "jobCode={0},error={1}"),
	CHECK_JOBPROCESS_BEAN_ERROR("40004", "jobCode={0},jobProcessBean={1},error={2}"), 
	CHECK_STEPCODE_NOT_EMPTY("40005", "stepCode is empty"),
	CHECK_STEPCODE_NOT_EXIST("40006", "stepCod={0} edoes not exist "),
	CHECK_STEPPROCESS_NOT_EMPTY("40007", "stepCode={0}, stepProcessBean is empty"),
	CHECK_STEPPROCESS_NOT_EXIST("40008", "stepCode={0}, stepProcessBean={1}, stepProcessBean does not exist"),
	CHECK_STEP_NOT_EMPTY("40009", "moduleCode={0},jobCode={1},error={2}"),
	
	SUBMIT_JOB_DUPLICATED("50001", "submit job failed, duplicated job"),
	SUBMIT_MODULE_ERROR("50002", "submit job failed,moduleCode={0},error={2}"),
	SUBMIT_JOB_ERROR("50003", "submit job failed,moduleCode={0},jobCode={1},error={2}"),
	SUBMIT_STEP_ERROR("50004", "submit step failed,moduleCode={0},jobCode={1},stepCode={2}, error={3}"),
	SAVE_JOB_ERROR("50005", "save job failed,moduleCode={0},jobCode={1},error={2}");

	private String code;
	private String pattern;

	ErrorCodeEnum(String code, String pattern) {
		this.code = code;
		this.pattern = pattern;
	}

	public String getCode() {
		return this.code;
	}
	
	public String getErrorMsg() {
		return this.getErrorMsg(new Object[0]);
	}
	
	public String getErrorMsg(Object... params) {
		String errorMsg = null;
		if (params == null || params.length == 0) {
			errorMsg = this.pattern;
		} else {
			MessageFormat msgFmt = new MessageFormat(this.pattern);
			errorMsg = msgFmt.format(params);
		}
		return errorMsg;
	}

	public String getErrorMsg(String... params) {
		String errorMsg = null;
		if (params == null || params.length == 0) {
			errorMsg = this.pattern;
		} else {
			MessageFormat msgFmt = new MessageFormat(this.pattern);
			errorMsg = msgFmt.format(params);
		}
		return errorMsg;
	}
}
